"""
@file pyTestPlayback.py
@authors Guillaume
@date august 8th, 2013
"""
import unittest

from pkPlayback import pkPlayback
from time import sleep
import sys
from PyQt4.QtGui import QApplication, QFrame
from PyQt4.QtCore import QCoreApplication



class TestPlayback(unittest.TestCase):

	def setUp(self):
		self.app = QApplication(sys.argv)
		self.app.setApplicationName("test - pkPlayback")
		#self.window = QFrame()
		#self.window.show()
		self.playback = pkPlayback()
		self.paths_to_test_songs = ["../test.mp3", "../test2.mp3", "../test.ogg"]
		self.playback.set_queue(self.paths_to_test_songs)


	def test_set_queue(self):
		result = self.playback.get_queue()
		expected = self.paths_to_test_songs[1:]
		self.assertEqual(result, expected)
		self.assertNotEqual(result, [])

	def test_change_queue(self):
		self.playback.set_queue(self.paths_to_test_songs[:2])
		expected = self.paths_to_test_songs[:2]
		result = self.playback.get_queue()
		self.assertEqual(result, expected)
		self.assertNotEqual(result, [])


if __name__ == "__main__":

	unittest.main()
	sys.exit(0)


	### SOUND TEST ###

	# Set-up Application
	application = QApplication(sys.argv)
	application.setApplicationName("pkPlayback - TEST")
	window = QFrame()
	window.show()
	#window.destroyed.connect(sys.exit(0))
	QApplication.quitOnLastWindowClosed() == True

	# Let's define our list to play
	paths_to_test_songs = ["../testSongs/test.mp3", "../testSongs/test.ogg", "../testSongs/test2.mp3"]

	# Instantiate the class to test
	playback = pkPlayback()

	# Set queue and actually test pkPlayback
	playback.set_queue(paths_to_test_songs)
	print("You are listening to", playback._media_object.currentSource().fileName())
	playback.play()

	application.exec_()
	sys.exit(0)
